package com.xysq.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ListView;

import com.rockcent.action.CallbackListener;
import com.rockcent.model.CustomerCouponBO;
import com.rockcent.model.TipsModel;
import com.xysq.adapter.TipsAdapter;
import com.xysq.lemon.R;
import com.xysq.util.UseUtil;
import com.xysq.util.UserInfoKeeper;

import java.util.ArrayList;
import java.util.List;

import butterknife.InjectView;

public class AuthorTipsActivity extends BaseActivity implements View.OnClickListener {

    @InjectView(R.id.ibtn_back)
    ImageButton backIbtn;
    @InjectView(R.id.list_tips)
    ListView tipsList;

    List<TipsModel> tipsModels = new ArrayList<>();
    TipsAdapter tipsAdapter;
    public int currentPage = 1;
    public static final String TYPE_SALING = "C01";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_author_tips);
        initView();
        loadData();
    }

    private void loadData() {
        loadTips();
    }

    private void loadTips() {
        appAction.listMyPublishedCoupons(UserInfoKeeper.readCustomerId(AuthorTipsActivity.this), "C01", currentPage, new CallbackListener<List<CustomerCouponBO>>() {
            @Override
            public void onSuccess(List<CustomerCouponBO> data) {
                if (data.size() != 0) {
                    tipsModels.clear();
                    for (int i = 0; i < data.size(); i++) {
                        TipsModel tipsModel = new TipsModel();
                        tipsModel.setContent(data.get(i).getIntroduce());
                        tipsModel.setName(UseUtil.selectName(data.get(i).getNickName(), data.get(i).getCustomerName(), data.get(i).getPhone()));
                        tipsModel.setSchool(data.get(i).getExtend1());
                        tipsModel.setTimes(data.get(i).getSaleCount());
                        tipsModel.setTitle(data.get(i).getName());
                        tipsModel.setHeadUrl(data.get(i).getHeadUrl());
                        tipsModel.setLogoUrl(data.get(i).getLogoUrl());
                        tipsModels.add(tipsModel);
                    }
                    tipsAdapter.notifyDataSetChanged();
                }
            }

            @Override
            public void onFailure(String errorCode, String message) {

            }
        });
    }

    private void initView() {
        backIbtn.setOnClickListener(this);
        tipsAdapter = new TipsAdapter(AuthorTipsActivity.this, tipsModels);
        tipsList.setAdapter(tipsAdapter);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ibtn_back:
                finish();
                break;
        }
    }
}
